*REPLICATION CODE FOR "Licensing Life-Saving Drugs for Developing Countries: Evidence from the Medicines Patent Pool" Figure 1

u country_drugs.dta, clear

*generate panel identifier*
gen id = product+country
encode id, gen(ID)
drop id


gen MPP_sublicense= MPP_down
replace MPP_sublicense=. if access==0
gen Bilateral_deal= bilateral
replace Bilateral_deal=. if access==0
gen Deals= deals
replace Deals=. if access==0


bys ID: gen year_=year if MPP==1
bys ID: egen year_switch=min(year_)
gen time_to_treat=year-year_switch



 
keep if priority_list==1

encode product, gen(product_code)
encode country, gen(country_code)

replace time_to_treat = 0 if missing(year_switch)
g treat = !missing(year_switch)

summ time_to_treat
g shifted_ttt = time_to_treat - r(min)
summ shifted_ttt if time_to_treat == -1
local true_neg1 = r(mean)

*USE THIS LINE FOR FIGURE 1 PANEL A
*reghdfe access ib`true_neg1'.shifted_ttt, a(ID year) vce(cluster product_code country_code)

*THIS IS LINE FOR FIGURE 1 PANEL B 
reghdfe deals ib`true_neg1'.shifted_ttt, a(ID year) vce(cluster product_code country_code)


g coef = .
g se = .

levelsof shifted_ttt, l(times)
foreach t in `times' {
	replace coef = _b[`t'.shifted_ttt] if shifted_ttt == `t'
	replace se = _se[`t'.shifted_ttt] if shifted_ttt == `t'
}


* Make confidence intervals
g ci_top = coef+1.96*se
g ci_bottom = coef - 1.96*se


keep time_to_treat coef se ci_*
duplicates drop

sort time_to_treat


summ ci_top
local top_range = r(max)
summ ci_bottom
local bottom_range = r(min)

twoway (sc coef time_to_treat, connect(line) scheme(s1mono)) ///
	(rcap ci_top ci_bottom time_to_treat)	///
	(function y = 0, range(time_to_treat)) ///
	(function y = 0, range(`bottom_range' `top_range') horiz), ///
	xtitle("Time to Treatment") caption("95% confidence intervals shown") legend(off) 

asdf


